package com.lzw.breezeNovel.webApp.service.impl.novel;

import com.lzw.breezeNovel.model.enums.novel.BookStatus;
import com.lzw.breezeNovel.webApp.mapper.novel.BookMapper;
import com.lzw.breezeNovel.webApp.service.novel.RecommenService;
import com.lzw.breezeNovel.webApp.vo.novel.BookVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 清风明月
 * @Package com.lzw.breezeNovel.webApp.service.novel.impl
 * @date 2025/3/6
 * @description
 */
@Service
@SuppressWarnings("all")
public class RecommenServiceImpl implements RecommenService {

    @Autowired
    private BookMapper bookMapper;

    /**
     * 获取推荐小说
     * @return
     */
    @Override
    public List<BookVo> getRecommendations() {
        // TODO: 实现推荐小说逻辑 ->暂时简单处理
        List<BookVo> books = bookMapper.selectgetAllBook();
        if(!books.isEmpty()){
            //循环遍历
            List<BookVo> bookVos = books.stream().map(book -> {
                 //创建BookVo对象
                BookVo bookVo = new BookVo();
                //进行对象的拷贝
                bookVo.setBookId(book.getBookId());
                //获取小说的状态
                String status = BookStatus.getDescByCode(Integer.valueOf(book.getStatus()));
                //设置小说的状态
                bookVo.setStatus(status);
                //进行数据拷贝
                BeanUtils.copyProperties(book,bookVo);
                return bookVo;
             }).filter(bookVo -> bookVo != null).collect(Collectors.toList());
            //返回对象
            return bookVos;
        }
        //返回空集合
        return List.of();
    }
}
